package com.shd.edanpei.view.pop;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.shd.edanpei.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mc on 2018/9/18.
 * yang-wen-wen
 */

public class FilterPop extends PopupWindow {

    //布局填充器
    private LayoutInflater mInflater;
    //上下文
    private Context mContext;
    //只显示String类型的数据
    private List<String> mDatas = new ArrayList<>();
    //pop整体View
    private View popupView;
    //选择条件的list
    private ListView listView;
    //筛选条件后的回调
    AdapterView.OnItemClickListener itemClickListener;
    //适配器
    FilterPopAdapter mAdapter;

    public FilterPop(Context context, List<String> mDatas) {
        this.mInflater = LayoutInflater.from(context);
        this.mContext = context;
        this.mDatas = mDatas;
        popupView = mInflater.inflate(R.layout.popup_dialog, null);
        //设置View
        this.setContentView(popupView);
        //设置弹出窗体的宽高
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        //初始化控件
        initPopView();
        this.setFocusable(true);
        this.setTouchable(true);
        this.setOutsideTouchable(true);
        this.setBackgroundDrawable(new BitmapDrawable());
        this.setAnimationStyle(R.style.FilterPop_Animation);
        this.update();
    }

    private void initPopView() {
        listView = popupView.findViewById(R.id.list_view);
        mAdapter = new FilterPopAdapter(mContext, mDatas);
    }

    public void setOnItemSelectedListener(AdapterView.OnItemClickListener listener) {
        if (null != itemClickListener && null != listView) {
            listView.setOnItemClickListener(itemClickListener);
        }
    }
}
